import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:project_fw_net_class/http/core/fw_net.dart';
import 'package:project_fw_net_class/http/request/test_request.dart';
import 'package:project_fw_net_class/model/owner.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  @override
  void initState() {
    super.initState();
  }

  void _incrementCounter() async {
    // test();
    test2();
  }

  void test() {
    TestRequest request = TestRequest();
    request.add("aid", 7);
    print("url:${request.url()}");
    var fire = FwNet.getInstance().fire(request);

    print("result:$fire");
  }

  void test2() {
    const jsonString =
        "{ \"name\": \"flutter\", \"url\": \"https://coding.imooc.com/class/487.html\" }";
    //json转map
    Map<String, dynamic> jsonMap = jsonDecode(jsonString);
    var owner = Owner.fromJson(jsonMap);
    var string = owner.toJson();
    //需要转成一个pojo bean model  fastjson  gson
    //反射做处理
    //dart--生产环境反射禁用
    //APT
    //
    print('name:${jsonMap['name']}');
    print('url:${jsonMap['url']}');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
